﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YAPL.Language.Ast;

namespace YAPL.Language.SourceParser.Helpers {
	public static class OperatorHelper {
		private static readonly Dictionary<string, BinaryOperator> _binaryOperators =
			new Dictionary<string, BinaryOperator>();
		private static readonly Dictionary<string, UnaryOperator> _unaryOperators =
			new Dictionary<string, UnaryOperator>();
		static OperatorHelper() {
			_binaryOperators.Add("+", BinaryOperator.Plus);
			_binaryOperators.Add("-", BinaryOperator.Minus);
			_binaryOperators.Add("*", BinaryOperator.Multiply);
			_binaryOperators.Add("/", BinaryOperator.Divide);
			_binaryOperators.Add("%", BinaryOperator.Mod);
			_binaryOperators.Add("&&", BinaryOperator.And);
			_binaryOperators.Add("||", BinaryOperator.Or);

			_unaryOperators.Add("+", UnaryOperator.Plus);
			_unaryOperators.Add("-", UnaryOperator.Minus);
			_unaryOperators.Add("++", UnaryOperator.Increment);
			_unaryOperators.Add("--", UnaryOperator.Decrement);
			_unaryOperators.Add("!", UnaryOperator.Not);
		}

		public static BinaryOperator ParseBinaryOperator(string op) {
			return _binaryOperators[op];
		}

		public static UnaryOperator ParseUnaryOperator(string op) {
			return _unaryOperators[op];
		}
	}
}
